<?php if($this->errMsg) :?>
	<?php $this->showError($this->errMsg)?>
<?php endif; ?>
<?php if($this->msg) :?>		
	<?php $this->showMessage($this->msg)?>	
<?php endif;?>
<?php
if($this->forum)
{
$hide = "";$show = "";
if($this->forum['status'] == 0)
	$hide = "selected";
else
	$show = "selected";
?>
<form name='form' id='form' action="" method="POST">
	<div class="title_ad"><label><a href="">Sửa chuyên mục</a></label>
	</div>
	<div class="mydiv">
	<table  class="tb_box">
		<tr>
			<td>
				<label>Mã Chuyên mục :</label>
			</td>
			<td>
				<input readonly="readonly" type="text" name ="id" value = "<?php echo $this->forum['id'];?>">
			</td>
			<td>
				<label>Tên chuyên mục</label>
			</td>
			<td>
				<input type="text" name ="name" value = "<?php echo $this->forum['name']?>">
			</td>
		</tr>
		<tr>
			<td>
				<label>Trạng Thái</label>
			</td>
			<td colspan="3">
			<select name = 'status'>
				<option value = '0' <?php echo $hide?>>Ẩn</option>
				<option value= '1' <?php echo $show?>>Hiện</option>
			</select>
			</td>
		</tr>
	</table>
	<?php if($this->forum['id'] != 1)
		echo('
	<div class="div_button" >	
		<input type="submit" value="Lưu" class="button"/>
		<input type="reset" value="Làm lại" class="button" />
	</div>');
	?>
	
		<div id="contenSort" align="center">
			<fieldset id="info">
			<legend >Sắp xếp thứ tự xuất hiện</legend>
				<ul class="ui-sortable">
					<?php 
					foreach($this->arrtypenewssort as $row)
					{
						echo "<li id='id_$row->id'>$row->name</li>";
					}
					?>
				</ul>
				<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/typenews/new/forum_id/<?php echo $this->forum['id'];?>"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>
			</fieldset>		
		</div>
		<table  class="display" id="list">
	<thead>
		<tr>
			<th width="10px">ID</th>
			<th>Name</th>
			<th width="130px">Status</th>
			<th width="80px" style="text-align: center;">Tool</th>
		</tr>
	</thead>
	<tbody>
	<?php
		foreach ($this->arrtypenews as $row)
		{
			$status = "";
			if($row->status == 1)
				$status = 'Hiện <a style="float:right;" href="javascript:hide('.$row->id.')" title="Ẩn comment này"><img src="'.$this->baseUrl().'/public/images/Unbanned.png"></img></a>';
			else
				$status = 'Ẩn <a style="float: right;" href="javascript:show('.$row->id.')" title="Hiện comment này"><img src="'.$this->baseUrl().'/public/images/Banned.png"></img></a>';
			echo("<tr>");
			echo(	"<td>".$row->id."</td>");
			echo(	"<td>".$row->name."</td>");
			echo(	"<td id='active_".$row->id."'>".$status."</td>");
			echo(	'<td><a href="'.$this->baseUrl().'/admin/typenews/edit/id/'.$row->id.'" title="Edit" class="tool-16 edit"></a>&nbsp;&nbsp;
					<a href="javascript:del('.$row->id.')" title="Delete" class="tool-16 delete"></a></td>');
			echo("</tr>");
		}
	?>
	</tbody>
</table>
		<div class="clear"></div>
	</div>
</form>
<?php 
}
else
	echo ('Chuyên mục này không tồn tại');
?>
<script>
$(document).ready(function(){
	$(function(){
		$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize"); 
			$.post("<?php echo $this->baseUrl.'/admin/Typenews/sort'?>", order, function(theResponse){
				
			}); 															 
		}								  
		});
	});
});


function hide(key){
	if(!confirm("bạn muốn ẩn loại tin này không?"))
		return;
	var idforum = $("input[name='id']").val();
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/Typenews/status'?> ",
		data: "id=" + key +"&status=0&idforum="+idforum,	
		dataType: 'json',
		success: function(msg){
			if(msg)
			{	
				var data ='<fieldset id="info">';
				data += '<legend >Sắp xếp thứ tự xuất hiện</legend>';
				data += '	<ul class="ui-sortable">';
				$.each(msg, function(key, value){ 
					data += "<li id='id_"+value['id']+"'>"+value['name']+"</li>";
				});
				data += '	</ul>';
				data += '	<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/forum/new"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>';
				data += '</fieldset>	';	
				data += '	<div class="clear"></div>';
				$('#contenSort').html(data);
				$(function(){
					$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
						var order = $(this).sortable("serialize"); 
						$.post("<?php echo $this->baseUrl.'/admin/Typenews/sort'?>", order, function(theResponse){
							
						}); 															 
					}								  
					});
				});
				$('#active_'+key).html('Ẩn<a style="float: right;" href="javascript:show('+key+')" title="Hiện chuyên mục này"><img src="<?php echo ($this->baseUrl().'/public/images/banned.png') ?>"></img></a>');
			}else
				alert('Error');
		}
	});
}

function show(key){
	if(!confirm("bạn muốn hiện chuyêm mục này không?"))
		return;
	var idforum = $("input[name='id']").val();
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/Typenews/status'?> ",
		data: "id=" + key +"&status=1&idforum="+idforum,
		dataType: 'json',	
		success: function(msg){
			if(msg)
			{	
				var data ='<fieldset id="info">';
				data += '<legend >Sắp xếp thứ tự xuất hiện</legend>';
				data += '	<ul class="ui-sortable">';
				$.each(msg, function(key, value){ 
					data += "<li id='id_"+value['id']+"'>"+value['name']+"</li>";
				});
				data += '	</ul>';
				data += '	<a style="text-align:right;float:right;margin-right:20px;" href="<?php echo $this->baseUrl()?>/admin/forum/new"><img src="<?php echo $this->baseUrl()?>/application/templates/admin/images/plus_32.png" /></a>';
				data += '</fieldset>	';	
				data += '	<div class="clear"></div>';
				$('#contenSort').html(data);
				$(function(){
					$("#contenSort ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
						var order = $(this).sortable("serialize"); 
						$.post("<?php echo $this->baseUrl.'/admin/Typenews/sort'?>", order, function(theResponse){
							
						}); 															 
					}								  
					});
				});
				$('#active_'+key).html('Hiện<a style="float: right;" href="javascript:hide('+key+')" title="Ẩn chuyện mục này"><img src="<?php echo ($this->baseUrl().'/public/images/Unbanned.png') ?>"></img></a>');
			}else
				alert('Error');
		}
	});
}

function del(key){
	if(!confirm("Bạn muốn xóa chuyên mục này không?"))
		return;
	$.ajax({
		type: "POST",
		url:"<?php echo $this->baseUrl.'/admin/Typenews/delete'?> ",
		data: "id=" + key,	
		success: function(msg){
			if(msg == '1')
				location.replace("<?php echo $this->baseUrl.'/admin/forum/edit/id/'.$this->forum['id']?>");
			else
				alert('Error');
		}
	});
}

</script>